package com.guc.coroutines.vm

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.guc.coroutines.bean.AppInfo
import kotlinx.coroutines.launch
import net.Api

/**
 * Created by guc on 2021/9/15.
 * Description：
 */
class AppInfoViewModel : ViewModel() {
    private val _appInfo = MutableLiveData<List<AppInfo>>()
    val appInfo = _appInfo
    fun getAppInfo() {
        viewModelScope.launch {
            val data = try {
                Api.getAppInfo()
            } catch (e: Exception) {
                e.printStackTrace()
                listOf()
            }
            Log.e("AppInfoViewModel","viewModelScope: ${Thread.currentThread().name}")
            appInfo.postValue(data)
        }
    }
}